﻿using MahApps.Metro.Controls;
using SQX.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SQX.DataModel;

namespace SQX.Views
{
    /// <summary>
    /// Interaction logic for Connection.xaml
    /// </summary>
    public partial class Connection : MetroWindow
    {        
        public Connection(Service.SourceType ConnectionType)
        {
            InitializeComponent();
            this.DataContext = new ConnectionViewModel(ConnectionType);
        }

        private void Connect_Click(object sender, RoutedEventArgs e)
        {
            (this.DataContext as ConnectionViewModel).ActionResult = true;
            this.Close();
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            (this.DataContext as ConnectionViewModel).ActionResult = false;
            this.Close();
        }

        private void cubeInput_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                (this.DataContext as ConnectionViewModel).ActionResult = true;
                this.Close();
            }
        }

        private void dbInput_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                (this.DataContext as ConnectionViewModel).ActionResult = true;
                this.Close();
            }
        }

        private void serverInput_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                (this.DataContext as ConnectionViewModel).ActionResult = true;
                this.Close();
            }
        }
    }
}
